/**
 * Copyright (c) 2023 myons Inc. All rights reserved.
 */
package cn.zmwh.im.server.config;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;

/**
 * @describe: 强制路由、
 * @author: dmzmwh 、
 * @time: 2023-12-28 11:46 、
 */
@Slf4j
public class HintManager implements AutoCloseable {

    public static HintManager getInstance() {
        HintManager result = new HintManager();
        return result;
    }

    public void addDbValue(String logicTable, Integer value) {
        DynamicDataSourceContextHolder.clear();
        DynamicDataSourceContextHolder.push(logicTable + "_" + value);
        log.info(logicTable + "切换" + value);
    }


    public void addTableValue(Integer value) {
        DpTableNameHandler.clear();
        DpTableNameHandler.setData(value);
    }


    public static void clear() {
        DynamicDataSourceContextHolder.clear();
        DpTableNameHandler.clear();
    }


    @Override
    public void close() {
        clear();
    }
}